import http from './interface'
import store from '@/store'
//设置请求前拦截器
http.interceptor.request = (config) => {
	console.log("====--++++++--"+store.state.userInfo.token)
	config.header = {
		'token': store.state.userInfo.token,
	}

}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	console.log("=============--------"+store.state.userInfo.token)
	uni.hideLoading()
	if(response.statusCode === 200){
		if ( response.data.code === 20001 || response.data.code === 20002) {
			//未登录
			uni.showToast({
				title: response.data.message,
				duration: 1200,
				icon: 'none'
			})
		setTimeout(function() {
			uni.reLaunch({
				url: '/pages/mine/auth',
				animationType: 'slide-in-bottom',
				"animationDuration": 450
			});
			console.log('拦截拦截拦截')
		}, 450);
			store.commit('logout')
			return
		}
	}else{
		uni.showToast({
			title: '网络好像不太通畅~',
			duration: 1200,
			icon: 'none'
		})
	}

}

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 *
 */

export const getClassOrActivityListByShopIdAndClassifyId = (data) => {
	return http.request({
		url: 'api/v1/pri/class_or_activity/getClassOrActivityListByShopIdAndClassifyId',
		method: 'POST',
		data
	})
}
export const getUserInfo = (data) => {
	return http.request({
		url: 'api/user/getUserInfo',
		method: 'POST',
		data,
	})
}
export const getClassOrdersList = (data,pageNum,pageSize) => {
     http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/getClassOrActivityOrdersList',
		method: 'POST',
		data,
	})
}
export const getClassNameAndClassifyIdByShopId = (data) => {
	return http.request({
		url: 'api/v1/pri/class_or_activity/getClassNameAndClassifyIdByShopId',
		method: 'POST',
		data
	})
}
export const getClassOrActivityInfo = (data) => {
	return http.request({
		url: 'api/v1/pri/class_or_activity/getClassOrActivityInfo',
		method: 'POST',
		data,
	})
}
export const getScheduleByDate = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/getScheduleByDate',
		method: 'POST',
		data,
	})
}
export const getScheduleByMonth = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/schedule',
		method: 'POST',
		data,
	})
}
export const applyActivity = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/payOrders',
		method: 'POST',
		data,
	})
}
export const createOrders = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/createOrders',
		method: 'POST',
		data,
	})
}
export const getLeaveApplyType = (data) => {

	return http.request({
		url: '/api/pri/leave_apply/getLeaveApplyType',
		method: 'GET',
		data,

	})
}
export const getApplyRecord = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token': store.state.userInfo.token
		}
	}
	return http.request({
		url: '/api/activity/getApplyRecord',
		method: 'POST',
		data,

	})
}
export const getClassTeacher = (data) => {
	return http.request({
		url: '/api/pri/leave_apply/getClassTeacher',
		method: 'POST',
		data,

	})
}
export const getMessageToList = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: '/api/pri/message_admin/getMessageToList',
		method: 'POST',
		data,

	})
}
export const getMessageToInfo = (data) => {
	return http.request({
		url: '/api/pri/message_admin/getMessageToInfo',
		method: 'POST',
		data,

	})
}
export const submitLeaveApply = (data) => {
	return http.request({
		url: '/api/pri/leave_apply/submitLeaveApply',
		method: 'POST',
		data,

	})
}
export const getLeaveApplyLog = (data) => {
	return http.request({
		url: '/api/pri/leave_apply/getLeaveApplyLog',
		method: 'POST',
		data,

	})
}
export const getClassOrdersListInfo = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/getClassOrActivityOrdersInfo',
		method: 'POST',
		data,
	})
}
export const ClassOrActivityRefund = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/ClassOrActivityRefund',
		method: 'POST',
		data,
	})
}
export const ClassOrActivityRefundInfo = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/ClassOrActivityRefundInfo',
		method: 'POST',
		data,
	})
}
export const cancelRefund = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/cancelRefund',
		method: 'POST',
		data,
	})
}
export const cancelOrders = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/cancelOrders',
		method: 'POST',
		data,
	})
}
export const getMyClass = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/getMyClass',
		method: 'POST',
		data,
	})
}
export const classStudents = (data) => {

	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/classStudents',
		method: 'POST',
		data,
	})
}
export const getClassMessage = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/pri/message_admin/getClassMessage',
		method: 'POST',
		data,

	})
}
export const sendMessage = (data) => {

	return http.request({
		url: 'api/pri/message_admin/sendMessage',
		method: 'POST',
		data,

	})
}
export const getClassSign = (data) => {
	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/getClassSign',
		method: 'POST',
		data,

	})
}
export const getLeaveLog = (data) => {

	return http.request({
		url: '/api/pri/leave_apply/getLeaveLog',
		method: 'POST',
		data,

	})
}
export const getLeaveLogInfo = (data) => {

	return http.request({
		url: '/api/pri/leave_apply/getLeaveLogInfo',
		method: 'POST',
		data,

	})
}
export const passOrRefuseLeave = (data) => {

	return http.request({
		url: '/api/pri/leave_apply/passOrRefuseLeave',
		method: 'POST',
		data,

	})
}
export const getClassOrActivityList = (data) => {

	return http.request({
		url: 'api/v1/pri/class_or_activity/getClassOrActivityList',
		method: 'POST',
		data,
	})
}
export const getMessageFromList = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/pri/message_admin/getMessageFromList',
		method: 'POST',
		data,

	})
}
export const getMessageFromInfo = (data) => {
	return http.request({
		url: 'api/pri/message_admin/getMessageFromInfo',
		method: 'POST',
		data,

	})
}
export const updateUserInfo = (data) => {
	return http.request({
		url: 'api/user/updateUserInfo',
		method: 'POST',
		data,
	})
}
export const updateidcard = (data) => {
	return http.request({
		url: 'api/user/update_id_card',
		method: 'POST',
		data,
	})
}
export const signUpOrOut = (data) => {
	return http.request({
		url: 'api/v1/pri/orders_class_or_activity/signUpOrOut',
		method: 'POST',
		data,
	})
}
export const topUpIntegral = (data) => {
	uni.showLoading({
		title: '加载中',
		mask: true
	})
	return http.request({
		url: 'api/pri/AccumulatePoints/topUpIntegral',
		method: 'POST',
		data,
	})
}
export const getTeacherScheduleByDate = (data) => {
	return http.request({
		url: '/api/v1/pri/orders_class_or_activity/getTeacherScheduleByDate',
		method: 'POST',
		data,

	})
}
export const getScheduleDate = (data) => {
	return http.request({
		url: '/api/v1/pri/orders_class_or_activity/getScheduleDate',
		method: 'POST',
		data,

	})
}
export const getTeacherInfo = (data) => {
	return http.request({
		url: 'api/v1/pri/class_or_activity/getTeacherInfo',
		method: 'POST',
		data,

	})
}
export default {
	getUserInfo,
	getClassOrdersList,
	getClassOrActivityInfo,
	getClassNameAndClassifyIdByShopId,
	getClassOrActivityListByShopIdAndClassifyId,
	getScheduleByDate,
	getScheduleByMonth,
	applyActivity,
	createOrders,
	getLeaveApplyType,
	getApplyRecord,
	getClassTeacher,
	getMessageToList,
	getMessageToInfo,
	submitLeaveApply,
	getLeaveApplyLog,
	getClassOrdersListInfo,
	ClassOrActivityRefund,
	ClassOrActivityRefundInfo,
	cancelRefund,
	cancelOrders,
	getMyClass,
	classStudents,
	getClassMessage,
	sendMessage,
	getClassSign,
	getLeaveLog,
	getLeaveLogInfo,
	passOrRefuseLeave,
	getClassOrActivityList,
	getMessageFromList,
	getMessageFromInfo,
	updateUserInfo,
	updateidcard,
	signUpOrOut,
	topUpIntegral,
	getTeacherScheduleByDate,
	getScheduleDate,
	getTeacherInfo
}
